<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input v-model="filters.account" placeholder="账号"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="findList">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="addCompany">新增</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <!--列表-->
    <el-table
      :data="list"
      highlight-current-row
      v-loading="listLoading"
      style="width: 100%;"
      height="70vh"
    >
      <el-table-column prop="account" label="账号" align="center"></el-table-column>
      <!-- <el-table-column label="员工姓名" align="center">
        <template slot-scope="scope">
            <div>
                <p>{{scope.row.psnname == 'Assign'?'': scope.row.psnname}}</p>
            </div>
        </template>
      </el-table-column> -->
      <!-- <el-table-column prop="password" label="密码" align="center"></el-table-column> -->
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="danger" size="small" @click="handEdit(scope.row,1)">编辑</el-button>
          <el-button type="danger" size="small" @click="handEdit(scope.row,2)">修改密码</el-button>
          <el-button size="small" @click="handDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-col :span="24" class="toolbar">
      <!-- <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button> -->
      <el-pagination
        layout="prev, pager, next"
        @current-change="handleCurrentChange"
        :page-size="pageSize"
        :total="total"
        style="float:right;"
        :current-page="page"
      ></el-pagination>
    </el-col>
    <!--新增 编辑界面-->
    <el-dialog title="用户" :visible.sync="addFormVisible" :close-on-click-modal="false">
      <addAccount @hideTotas="hideTotas" v-if="addFormVisible" :sendFormData="sendFormData"></addAccount>
    </el-dialog>
  </section>
</template>

<script>
import addAccount from "./components/addAccount";
import { userList, userRemove ,smUserList, } from "../../api/baseSetting";

export default {
  data() {
    return {
      filters: {
        account: ""
      },
      addFormVisible: false,
      list: [],
      total: 0,
      page: 1,
      pageSize:10,
      listLoading: false,
      //点中的参数
      sendFormData: {}
    };
  },
  components: {
    addAccount
  },
  methods: {
    //点击删除
    handDelete(e) {
      let userId = e.userId;
      this.$confirm("确认删除该菜单", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          userRemove({userId:userId}).then(res => {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.filters.account = "";
            this.page = 1;
            this.getList();
          });
        })
        // .catch(() => {
        //   this.$message({
        //     type: "fail",
        //     message: "删除失败!"
        //   });
        //   this.page = 1;
        //   this.filters.account = "";
        //   this.getList();
        // });
    },
    //点击编辑
    handEdit(detail,type) {//1编辑  2修改密码
      this.sendFormData = detail;
      this.sendFormData.isType = type;
      this.addFormVisible = true;
    },
    //分页
    handleCurrentChange(val) {
      this.page = val;
      this.getList();
    },
    //隐藏新增表单
    hideTotas() {
      this.addFormVisible = false;
      this.filters.account = "";
      this.page = 1;
      this.getList();
    },
    //点击新增
    addCompany() {
      this.sendFormData = {};
      this.sendFormData.isType = 0;
      this.addFormVisible = true;
    },
    //点击查询
    findList() {
      this.page = 1;
      this.getList();
    },
    //获取账号列表
    getList() {
      let para = {
        account:this.filters.account,
        page: {
          page: this.page,
          pageSize: this.pageSize
        }
      };
      this.listLoading = true;
      userList(para)
        .then(res => {
          this.listLoading = false;
          this.list = res.records;
          this.total = res.total;
        })
        .catch(err => {
          this.listLoading = false;
        });
    }
  },
  mounted() {
    this.getList();
  }
};
</script>
<style lang="less" scoped>
</style>
